import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

try {
    if(localStorage){}
}catch(e) {}

export default new Vuex.Store({
    state: {
        user: {},
        token: localStorage.token 
    },
    actions: {
        // change (ctx,value) {
        //     ctx.commit('change',value)
        // }
    },
    mutations: {
        // state 是共用数据
        // change (state, value) {
        //     state.value =  value
        // },
        setToken (state,value){
            state.token = value
            localStorage.token =value
        },
        setUser(state,value) {
            state.user = value
        },
        removeToken(state,value) {
            localStorage.removeItem("token")
            state.token= undefined
            state.user = {}
        }
        
    }

})
